#include "logo.h"

char *butlast(void)
{
     int i;
     int k;
     char *ans;
     char *val;
     char valStr[MAXVALUE] ="\0";
     char ansStr[MAXVALUE] ="\0";

     val =valStr;
     ans =ansStr;
     strcpy(val,getValue());
     printf("string of last is %s\n",val);
     if (val[0] == '[')
     {
        i=strlen(val)-2;
        k=0;
        while (i>0)
        {
              if ((!k)&&(i<strlen(val)-2)&&((val[i] ==' ')||(val[i] ==']')))
              {
                 break;
              }else if (val[i] ==']')
              {
                    k++;
              }else if (val[i] =='[')
              {
                    k--;
              }
              i--;
        }
        while (isspace(val[i]))
        {
              i--;
        }
        strcpy(ans,val);
        ans[i+1] ='\0';
        strcat(ans,"]");
        goto RE;
     }

     strcpy(ans,val);
     ans[strlen(ans)-1] ='\0';

     RE:
            return ans;
}
